!<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    div {
      width: 200px;
      height: 50px;
      display: flex;
      margin: 50px;
    }

    div > input {
      width: 100px;
      text-align: center;
      font-size: 20px;
    }

    div > button {
      width: 50px;
      height: 50px;
      font-size: 22px;
    }
  </style>
</head>
<body>

  <div>
    <button class="sub">-</button>
    <input  type="text" value="1">
    <button class="add">+</button>
  </div>

  <div>
    <button class="sub2">-</button>
    <input class="second" type="text" value="1">
    <button class="add2">+</button>
  </div>

    <script>
        function outer(){
            let count = 1;
            return {
                set Count(val){
                    count = val
                },
                get Count(){
                    return count;
                }
            }
        }


        const box1 = outer();
        const subBtn = document.querySelector('.sub');
        const addBtn = document.querySelector('.add');
        const inp =  document.querySelector('input');
        subBtn.addEventListener('click',function(){
            let num = box1.Count;  
            if(num<=1){
                box1.Count = 1
                inp.value = box1.Count;
            }else{
                box1.Count = num-1;
                inp.value = box1.Count;
            }
            
            
        })
        addBtn.addEventListener('click',function(){
            let num = box1.Count;
            if(num>=20){
                box1.Count = 20;
                inp.value = box1.Count;
            }
            else{
                box1.Count = num+1;
                inp.value = box1.Count;
            }
        })


        const box2 = outer();
        const subBtn2 = document.querySelector('.sub2');
        const addBtn2 = document.querySelector('.add2');
        const inp2 =  document.querySelector('.second');


        subBtn2.addEventListener('click',function(){
            let num = box2.Count;  
            if(num<=1){
                box2.Count = 1;
                inp2.value = box2.Count;
            }else{
                box2.Count = num-1;
                inp2.value = box2.Count;
            }
            
            
        })
        addBtn2.addEventListener('click',function(){
            let num = box2.Count;
            if(num>=20){
                box2.Count = 20;
                inp2.value = box2.Count;
            }
            else{
                box2.Count = num+1;
                inp2.value = box2.Count;
            }
        })
    </script>
</body>
</html>